﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RegisterCodeGenerator
{
    public class Generator
    {
        string content;
        public List<RegisterCodeGenerator.Register> Registers { get; set; }
        public void Init(string content)
        {
            Registers = new List<Register>();
            this.content = content;
            Register currentRegister=null;
            string[] buffer = content.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
            bool isFirstLine = true;
            foreach (var line in buffer)
            {
                if (isFirstLine)// skip first line
                {
                    isFirstLine = false;
                    continue;
                }
                string[] items = line.Split(',');
                if (items[0]!=string.Empty)//address!=null, register definition found
                {
                    Register r = new Register(items);
                    Registers.Add(r);
                    currentRegister = r;
                }
                else
                {
                    BitMask b = new BitMask(items);
                    currentRegister.BitMasks.Add(b);
                }
            }

        }
        
    }
}
